#include <stdio.h>
#define MAXTITL 40
#define MAXAUTL 40
#define MAXBKS 2 //容纳图书册书
struct book{ //定义结构
	char title[MAXTITL];
	char author[MAXAUTL];
	float value;
};
int main(){
	struct book library[MAXBKS]; //定义结构变量
	int count=0; //存储书本计数器
	int index; //打印目录所用计数器

	printf("Plese ente the book title.\n");
	printf("Press [enter] at the start of a line to stop.\n");
	while(count < MAXBKS && gets(library[count].title)!=NULL&&library[count].title[0]!='\0'){ 
	/*while循环条件分别为：1.当前输入数本册书小于书库最大可容纳书本册书
		                 2.library[count].title当前值不为空
		                 3。title首字符不为'\0'*/
		printf("Now enter the author.\n");
		gets(library[count].author);
		printf("Now enter the value.\n");
        scanf("%f",&library[count++].value);
		while(getchar()!='\n')
			continue;//遇上换行符时跳出while循环
		if(count < MAXBKS)
			printf("Enter the next title.\n");
	}
	if(count>0){
		printf("Here is the list of your books:\n");
		for(index = 0;index < count;index ++){
			printf("%s by %s: %.2f\n", library[index].title, 
				library[index].author , library[index].value);
		}
	}
	else printf("NO Book\n");
		return 0;
}